package org.hongzhisoft.dis.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hongzhisoft.dis.bean.Role;
import org.hongzhisoft.dis.service.RoleService;
import org.hongzhisoft.dis.service.impl.RoleServiceImpl;

/**
 * 新增角色请求处理类
 * @author HongChengzhi
 *
 */
@WebServlet("/role/add")
public class RoleAddServlet extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private RoleService roleService = new RoleServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        String role_name = (String) req.getParameter("role_name");
        String role_key = (String) req.getParameter("role_key");
        String remark = (String) req.getParameter("remark");

        Role role = new Role();
        role.setRole_name(role_name);
        role.setRole_key(role_key);
        role.setRemark(remark);

        try {
            roleService.saveRole(role);//调用业务层，完成角色保存
            req.setAttribute("role_name", role_name);
            req.getRequestDispatcher("/addrole_success.jsp").forward(req, resp);
        } catch (Exception e) {
            throw new ServletException(e);
        }

    }

}
